/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package remoteEntity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author viktor
 */
@Entity
@Table(name = "filedescription")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Filedescription.findAll",           query = "SELECT f FROM Filedescription f"),
    @NamedQuery(name = "Filedescription.findById",          query = "SELECT f FROM Filedescription f WHERE f.id = :id"),
    @NamedQuery(name = "Filedescription.findByName",        query = "SELECT f FROM Filedescription f WHERE f.name = :name"),
    @NamedQuery(name = "Filedescription.findByDescription", query = "SELECT f FROM Filedescription f WHERE f.description = :description"),
    @NamedQuery(name = "Filedescription.findByCategoryId",  query = "SELECT f FROM Filedescription f WHERE f.categoryId = :categoryId"),
    @NamedQuery(name = "Filedescription.countByCategoryId",  query = "SELECT count(f) FROM Filedescription f WHERE f.categoryId = :categoryId"),
    @NamedQuery(name = "Filedescription.findByDatecreated", query = "SELECT f FROM Filedescription f WHERE f.datecreated = :datecreated")}) 
public class Filedescription implements Serializable {
    @Column(name = "datecreated")
    @Temporal(TemporalType.TIMESTAMP)
    private Date datecreated;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "filedescription")
    private Collection<Comment> commentCollection;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
    private Integer id;
    @Size(max = 45)
    @Column(name = "name")
    private String name;
    @Size(max = 200)
    @Column(name = "description")
    private String description;
    @JoinTable(name = "filedescription_has_tag", joinColumns = {
        @JoinColumn(name = "filedescription_id", referencedColumnName = "id")}, inverseJoinColumns = {
        @JoinColumn(name = "tag_id", referencedColumnName = "id")})
    @ManyToMany
    private Collection<Tag> tagCollection;
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "fileblob_id", referencedColumnName = "id")
    @ManyToOne(optional = false, fetch=FetchType.LAZY)
    private Fileblob fileblob;
    @Column(name = "category_id")
    private int categoryId;
    @JoinColumn(name = "category_id", referencedColumnName = "id", updatable=false, insertable=false)
    @ManyToOne(optional = false)
    private Category category;

    public Filedescription() {
    }

    public Filedescription(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public Collection<Tag> getTagCollection() {
        return tagCollection;
    }

    public void setTagCollection(Collection<Tag> tagCollection) {
        this.tagCollection = tagCollection;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Fileblob getFileblob() {
        return fileblob;
    }

    public void setFileblob(Fileblob fileblob) {
        this.fileblob = fileblob;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public int getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(int categoryId) {
        this.categoryId = categoryId;
    }

   
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Filedescription)) {
            return false;
        }
        Filedescription other = (Filedescription) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Filedescription[ id=" + id + " ]";
    }

    public Date getDatecreated() {
        return datecreated;
    }

    public void setDatecreated(Date datecreated) {
        this.datecreated = datecreated;
    }

    @XmlTransient
    public Collection<Comment> getCommentCollection() {
        return commentCollection;
    }

    public void setCommentCollection(Collection<Comment> commentCollection) {
        this.commentCollection = commentCollection;
    }
    
}
